var express = require("express");
var router = express.Router();
var pomelo = require("pomelo");

//通过id查询公告
router.get("/getAnnouncementById", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.announcementRemote.getAnnouncementById(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//查询所有公告
router.get("/getAllAnnouncements", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.announcementRemote.getAllAnnouncements(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//根据id修改公告
router.get("/updateAnnouncement", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.announcementRemote.updateAnnouncement(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//插入公告
router.get("/addAnnouncement", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.announcementRemote.addAnnouncement(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

//通过id删除公告
router.get("/deleteAnnouncementById", function(req, res) {
    var msg = req.query;
    pomelo.app.rpc.account.announcementRemote.deleteAnnouncementById(null, msg, function(data) {
        res.set({
            'content-type': 'application/json; charset=utf-8'
        }).send(JSON.stringify(data));
    });
});

module.exports = router;